home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
System Booster
/
System Booster.iso
/
Archives
/
ForCLI
/
0Utils13.lha
/
0Utils
/
ExpandArgs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-20
|
4KB
|
170 lines
/******************************************************************************
MODULE
ExpandArgs.c
DESCRIPTION
Does expanding of all arguments, that
contain wildcards and passing of all
other arguments.
NOTES
Kickstart 2.0+ required
compiles w/ SAS/C v6.51
BUGS
'ExpandArgs test c:b#? xyz' produced one
$80000004 when compiled w/ OPTIMIZE !???
TODO
!TESTING!
EXAMPLES
> ExpandArgs c:f#? xyz
c:Filenote
xyz
SEE ALSO
dos.library/MatchFirst, dos.library/MatchNext
INDEX
HISTORY
12-02-95 b_noll created
20-02-95 b_noll restructured source
21-02-95 b_noll added version/format-prefix/offset
20-03-95 b_noll added args diagnostics
AUTHOR
Bernd Noll, Brunnenstrasse 55, D-67661 Kaiserslautern
b_noll@informatik.uni-kl.de
******************************************************************************/
/**************************************
Includes
**************************************/
#ifndef EXEC_LIBRARIES_H
# include <exec/libraries.h>
#endif /* EXEC_LIBRARIES_H */
#ifndef CLIB_EXEC_PROTOS_H
# include <clib/exec_protos.h>
#endif /* CLIB_EXEC_PROTOS_H */
#ifndef DOS_DOS_H
# include <dos/dos.h>
#endif /* DOS_DOS_H */
#ifndef CLIB_DOS_PROTOS_H
# include <clib/dos_protos.h>
#endif /* CLIB_DOS_PROTOS_H */
#include <proto/dos.h>
#include <proto/exec.h>
/**************************************
Defines & Structures
**************************************/
#ifndef ABSEXECBASE
#define ABSEXECBASE ((struct ExecBase **)4L)
#endif
struct _arg {
/* ******************** USER FORMAT ******************** */
#define FORMAT "/A/M"
STRPTR *par;
#define MYFLAGS /* (APF_DOWILD|) APF_DODOT| APF_FollowHLinks| */ 0
#define LFORMAT "%s\n"
/* ******************** USER FORMAT ******************** */
}; /* struct _argv */
#define MAXPATHLEN 256
#define MAXLINELEN 256
#define VERSIONPREFIX "\0$VER: "
#define VERSIONOFFSET 0
#define FORMATPREFIX "\0$ARG: "
#define FORMATOFFSET 7
/**************************************
Implementation
**************************************/
long _main (void)
{
const char* version = VERSIONPREFIX "ExpandArgs 1.2 " __AMIGADATE__ + VERSIONOFFSET;
long retval = RETURN_FAIL;
struct ExecBase*SysBase = *ABSEXECBASE;
struct Library* DOSBase;
if (DOSBase = OpenLibrary (DOSNAME, 37)) {
struct _arg argv = { 0 };
APTR args;
retval = RETURN_ERROR;
if (args = (void*)ReadArgs(FORMATPREFIX FORMAT + FORMATOFFSET, (LONG*)&argv, NULL)) {
/* ******************** USER BODY ******************** */
BPTR stdout;
LONG error;
STRPTR pat;
//STRPTR lformat = LFORMAT;
#define lformat LFORMAT
int i;
struct AnchorPath *ap;
UBYTE apb[sizeof (*ap) + 8 + MAXPATHLEN];
//UBYTE buffer[MAXPATHLEN];
retval = RETURN_OK;
stdout = Output();
ap = (void *)(((ULONG)apb + 7) & ~7);
ap->ap_Strlen = MAXPATHLEN;
ap->ap_BreakBits = 0;
ap->ap_FoundBreak = 0;
//ap->ap_ = ;
for (i = 0; pat = argv.par[i]; i++) {
ap->ap_Flags = MYFLAGS;
for (error = MatchFirst(pat, ap); error == 0; error = MatchNext(ap)) {
FPrintf (stdout, lformat, ap->ap_Buf);
//FPrintf(Output(), "%ld\n", j++);
} /* for */
MatchEnd(ap);
if (error != ERROR_NO_MORE_ENTRIES) { /* abnormal error */
if ((error == ERROR_OBJECT_NOT_FOUND) && !(ap->ap_Flags & APF_ITSWILD)) {
FPrintf (stdout, lformat, pat);
} else {
retval = RETURN_ERROR;
break;
} /* if */
} /* if */
} /* for */
/* ******************** USER BODY ******************** */
FreeArgs (args);
} /* if */
if (retval > RETURN_WARN)
PrintFault(IoErr(), "ExpandArgs");
CloseLibrary (DOSBase);
} /* if */
return (retval);
} /* _main */
/******************************************************************************
***** END ExpandArgs.c
******************************************************************************/